<?php
namespace app\common\model;
use think\Request;

/**
 * 餐桌/包间模型
 */
class Table extends BaseModel
{
    protected $name = 'table';
	protected $append = ['code'];
	
	/**
     * 二维码
     */
    public function getCodeAttr($value, $data)
    {
        return web_url().'assets/qrcode/table/'.$data['table_id'].'.png';
    }

	/**
     * 关联门店
     */
    public function shop()
    {
        return $this->hasOne('Shop', 'shop_id', 'shop_id');
    }
	
    /**
     * 状态
     */
    public function getStatusAttr($value)
    {
        $status = [10 => '闲', 20 => '忙'];
        return ['text' => $status[$value], 'value' => $value];
    }

    /**
     * 获取列表
     */
    public function getList()
    {
        // 执行查询
        $list = $this->with(['shop'])
            ->order(['sort','table_id' => 'desc'])
            ->paginate(15, false, [
                'query' => Request::instance()->request()
            ]);
        return $list;
    }

    /**
     * 获取详情
     */
    public static function detail($table_id)
    {
        return self::get($table_id, ['shop']);
    }
}
